<template>
  <div class="eventLevel">
    <CommonBtn label-name="架构主数据维护" :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+item.value}}</span>
    </CommonBtn>
    <CommonList ref="list" :buttons="buttons" :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions"  @dbClick="openItem"></CommonList>
    <OrgPlanEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :original-data="row" 
                :button-event="button.event"
                :add-url="$api.API_ORG_ORGPLAN_ADD" 
                :edit-url="$api.API_ORG_ORGPLAN_UPDATE"
                :items="items"
                @editBack="editBack"
                @refresh="conditionChange"></OrgPlanEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_BUSETTING_EXPORT" :conditions="conditions"></CommonExport>

    <CommonInport :out-btn="button" @close="close" :inportUrl="inportUrl" :template-url="templateUrl" importMsg="insert"></CommonInport>
    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :delete-url="$api.API_ORG_ORGPLAN_DELETE"
                 :enable-url="$api.API_ORG_ORGPLAN_UPDATEORGPLANENABLE"
                 :disable-url="$api.API_ORG_ORGPLAN_UPDATEORGPLANDISABLE"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import OrgPlanEdit from "./OrgPlanEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import CommonInport from "../../common/CommonInport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'OrgPlan',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.DELETE,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.ENABLE,
                    this.$config.BTNS.DETAIL,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH,
                    this.$config.BTNS.ORGPLANINPORT
                ],
                columns:[
                    {
                        prop:'planName',
                        label:'方案名称',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'sortCode',
                        label:'排序'
                    },
                    {
                        prop:'valid',
                        label:'是否有效',
                        search:true,
                        type:'checkbox',
                        queryProp:'isValid'
                    },
                    {
                        prop:'memo',
                        label:'备注'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                listUrl: this.$api.API_ORG_ORGPLAN_LIST,
                inportUrl:'',
                templateUrl:'',
                button:null,
                conditions:[],
                row:{},
                items:[
                    {name:'方案名称',prop:'planName',type:'text',required:true,disable:false,placeholder:'请输入方案名称'},
                    {name:'排序',prop:'sortCode',type:'text',disable:true,readOnly:true,placeholder: '系统自动生成'},
                    {name:'备注',prop:'memo',type:'textarea',placeholder:'最多100个中文'},
                ],
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()' || item.event == 'Delete()' || item.event == 'disable()' || item.event == 'enable()' || item.event == 'detail()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }
                if(item == this.$config.BTNS.ORGPLANINPORT){
                    this.inportUrl=this.$api.API_POSRETAILER_IMPORT;
                    this.templateUrl = "/static/template/架构主数据导入模板.xlsx"
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
            },
            conditionChange(conditions) {
                this.row = null
                this.$refs.list.search()
            },
            close(item) {
                this.button = item
            },
            openItem(item) {
                this.button = this.$config.BTNS.DETAIL
            },
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,OrgPlanEdit,EnsurePopUp,CommonInport},
    }
</script>
